package chen.web.util;

import java.util.Calendar;
import java.util.Date;

/**
 * 计算星座和生肖
 * @author chen
 *
 */
public class Birthday {
	private static final String[] constellationArr = { "水瓶座", "双鱼座", "牡羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" };  
	private static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 }; 
	
	private static final String[] zodiacArr = { "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊" };  
	
	private Date date;
	public Birthday(Date date){
		this.date = date;
	}
	
	/**
	 * @param date
	 * @return	星座
	 */
	public String getConstellation(){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		int month = calendar.get(Calendar.MONTH);
		int day = calendar.get(Calendar.DAY_OF_MONTH);   
		if (day < constellationEdgeDay[month]) {   
			month = month - 1;   
		}
		 if (month >= 0) {   
		   return constellationArr[month];   
		 }
		 return constellationArr[11];  
	}
	
	 /**
	 * @param date
	 * @return	生肖
	 */
	public String getZodica() {  
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return zodiacArr[calendar.get(Calendar.YEAR) % 12];   
	 }   
}
